package com.kim.smartring.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.kim.smartring.application.SmartRingApplication;

public class SharedPreferencesUtils {

	private static final Context context = SmartRingApplication.CONTEXT;

	private SharedPreferencesUtils() {
	}

	/**
	 * 获取SharedPreferences
	 * 
	 * @param name
	 * @param mode
	 * @return
	 */
	public static SharedPreferences getSharedPreferences(String name, int mode) {
		return context.getSharedPreferences(name, mode);
	}

	public static void clearSharedPreferences(String name, int mode) {
		getSharedPreferences(name, mode).edit().clear().commit();
	}

	public static void setValueInPrivateMode(String key, String value,
			String sharedPreferencesName) {
		getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.edit().putString(key, value).commit();
	}

	public static void setValueInPrivateMode(String key, int value,
			String sharedPreferencesName) {
		getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.edit().putInt(key, value).commit();
	}

	public static void setValueInPrivateMode(String key, long value,
			String sharedPreferencesName) {
		getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.edit().putLong(key, value).commit();
	}

	public static void setValueInPrivateMode(String key, float value,
			String sharedPreferencesName) {
		getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.edit().putFloat(key, value).commit();
	}

	public static void setValueInPrivateMode(String key, boolean value,
			String sharedPreferencesName) {
		getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.edit().putBoolean(key, value).commit();
	}

	public static String getValueInPrivateMode(String sharedPreferencesName,
			String key, String defaultValue) {
		return getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.getString(key, defaultValue);
	}

	public static int getValueInPrivateMode(String sharedPreferencesName,
			String key, int defaultValue) {
		return getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.getInt(key, defaultValue);
	}

	public static long getValueInPrivateMode(String sharedPreferencesName,
			String key, long defaultValue) {
		return getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.getLong(key, defaultValue);
	}

	public static float getValueInPrivateMode(String sharedPreferencesName,
			String key, float defaultValue) {
		return getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.getFloat(key, defaultValue);
	}

	public static boolean getValueInPrivateMode(String sharedPreferencesName,
			String key, boolean defaultValue) {
		return getSharedPreferences(sharedPreferencesName, Context.MODE_PRIVATE)
				.getBoolean(key, defaultValue);
	}

}
